<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>proxy代理测试</title>
  </head>
  <body></body>
  <script>
    const user = {
      name: "jack",
      age: 20,
      car: {
        color: "black",
        price: 2000000,
      },
    };

    const proxy = new Proxy(user, {
      get(target, propName) {
        console.log("访问对象属性:", target, propName);
        return target[propName];
      },
      set(target, propName, value) {
        console.log(target, propName, value);
        target[propName] = value;
      },
    });

    console.log(proxy);
    console.log(proxy.age);
    proxy.hash = 2000;

    console.log(proxy);
  </script>
</html>
